package com.ming.controller;

import com.ming.mapper.CarMapper;
import com.ming.pojo.Car;
import com.ming.pojo.Owner;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/car")
public class CarController {

    @Autowired
    private CarMapper carMapper;

    /**
     * 通过车牌号获取业主信息 /模糊search
     * @param carLicenseId
     * @return
     */
    @RequestMapping("/blurryQueryOwnerByCarId")
    public List<Owner> blurryQueryOwnerByCarId(String carLicenseId) {
        carLicenseId = '%' + carLicenseId + '%';
        return carMapper.blurryQueryOwnerByCarLicense(carLicenseId);
    }



    /**
     * 添加业主车辆 /add
     * @param car
     */
    @RequestMapping("/addCar")
    public void addCar(Car car) {
        carMapper.addCar(car.getCarLicenseId(), car.getOwnerId());
    }

    /**
     * 删除业主车辆 /delete
     * @param car
     */
    @RequestMapping("/deleteCar")
    public void deleteCar(Car car) {
        carMapper.deleteCar(car.getCarLicenseId(), car.getOwnerId());
    }

    /**
     * 车辆列表
     */
    @RequestMapping("/carList")
    public List<Car> carList() {
       return carMapper.carList();
    }
}
